<?php declare(strict_types=1);

/**
 * @param $data
 * @param array $arr
 * @return array
 */
function descartes($data, array $arr = []): array
{
    $first = array_shift($data);
    $temp = [];
    if (count($arr) > 1) {
        foreach ($first as $val) {
            foreach ($arr as $val2) {
                $temp[] = $val2 .",". $val;
            }
        }
    } else {
        foreach ($first as $key=>$value) {
            $temp[] = $value;
        }
    }

    if (count($data) > 0) {
        $temp = descartes($data, $temp);
    }

    return $temp;
}

$res = descartes([['128G','256G','512G','1T'],['白色','黑色','蓝色','红色'],['国行','美版','港版'],['全网通']]);
echo '<pre>';
var_dump($res);